package com.cloud.custom.workflow.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.custom.common.result.Quokka;
import com.cloud.custom.workflow.command.assign.AssignCommand;
import com.cloud.custom.workflow.command.assign.AssignRequest;
import com.cloud.custom.workflow.command.assign.AssignResponse;
import com.cloud.custom.workflow.command.cancel.CancelCommand;
import com.cloud.custom.workflow.command.cancel.CancelRequest;
import com.cloud.custom.workflow.command.cancel.CancelResponse;
import com.cloud.custom.workflow.command.finish.FinishCommand;
import com.cloud.custom.workflow.command.finish.FinishRequest;
import com.cloud.custom.workflow.command.finish.FinishResponse;
import com.cloud.custom.workflow.command.rollback.RollbackCommand;
import com.cloud.custom.workflow.command.rollback.RollbackRequest;
import com.cloud.custom.workflow.command.rollback.RollbackResponse;
import com.cloud.custom.workflow.command.transit.TransitCommand;
import com.cloud.custom.workflow.command.transit.TransitRequest;
import com.cloud.custom.workflow.command.transit.TransitResponse;
import com.cloud.custom.workflow.service.WorkflowCoreService;

/**
 * 工作流相关操作
 * 
 * @author taominglong
 *
 */

@RestController
@RequestMapping("/custom/api/workflow")
public class WorkflowCoreController {

	@Autowired
	private WorkflowCoreService workflowCoreService;

	/**
	 * 批转
	 * 
	 * @param req 工作流批转相关参数
	 */
	@RequestMapping("transit")
	public Quokka transit(@RequestBody TransitRequest req) {
		TransitResponse resp = new TransitResponse();
		TransitCommand command = new TransitCommand();
		workflowCoreService.execute(req, resp, command);
		return new Quokka(true, resp);
	}
	
	/**
	 * 回退
	 * 
	 * @param req 工作流回退相关参数
	 * @return
	 */
	@RequestMapping("rollback")
	public Quokka rollback(@RequestBody RollbackRequest req) {
		RollbackResponse resp = new RollbackResponse();
		RollbackCommand command = new RollbackCommand();
		workflowCoreService.execute(req, resp, command);
		return new Quokka(true, resp);
	}
	
	/**
	 * 作废
	 * 
	 * @param req
	 * @return
	 */
	@RequestMapping("cancel")
	public Quokka cancel(@RequestBody CancelRequest req) {
		CancelResponse resp = new CancelResponse();
		CancelCommand command = new CancelCommand();
		workflowCoreService.execute(req, resp, command);
		return new Quokka(true, resp);
	}
	
	
	/**
	 * 办结
	 * 
	 * @param req
	 * @return
	 */
	@RequestMapping("finish")
	public Quokka finish(@RequestBody FinishRequest req) {
		FinishResponse resp = new FinishResponse();
		FinishCommand command = new FinishCommand();
		workflowCoreService.execute(req, resp, command);
		return new Quokka(true, resp);
	}
	
	/**
	 * 办理
	 * @param req
	 * @return
	 */
	@RequestMapping("assign")
	public Quokka assign(AssignRequest req) {
		AssignResponse resp = new AssignResponse();
		AssignCommand command = new AssignCommand();
		workflowCoreService.execute(req, resp, command);
		return new Quokka(true, resp);
	}
}
